/*
 * key.h
 *
 *  Created on: Apr 11, 2012
 *      Author: Tri_D
 */

#ifndef KEY_H_
#define KEY_H_

#include "main header.h"

#define		ZERO_KEY		PTAD_PTAD0
#define		TARE_KEY		PTAD_PTAD1
#define		NET_KEY			PTAD_PTAD2
#define		UNIT_KEY		PTAD_PTAD3
#define		FN_KEY			PTAD_PTAD4
#define		PRINT_KEY		PTAD_PTAD5

#define		MAX_HOLD_TIMER_COUNT	8				// can recognize holding down a key for 2 second maximum

typedef enum _Button_ID
{
	NO_BUTTON_ID,
	ZERO_BUTTON,
	TARE_BUTTON,
	NET_BUTTON,
	UNIT_BUTTON,
	FN_BUTTON,
	PRINT_BUTTON
} Button_ID_t;

/*
 * List of all the intent created by key press, key press sequences or holding down key(s)
 */
typedef enum _Key_Intent
{
	NO_INTENT = 0,
	ZERO_INTENT,
	TARE_INTENT,
	NET_INTENT,
	UNIT_INTENT,
	FN_INTENT,
	PRINT_INTENT,
	SETUP_INTENT,
	CLEAR_TARE_INTENT,
	PRINT_TARE_INTENT
} Key_Intent_t;

typedef struct _Button
{
	Button_ID_t ID;
	BOOL		bPress;
	uint8_t		holdtimer;
	uint8_t		Rebounce;
} Button_t;



typedef struct _Keybrd
{
	Button_t Zero;
	Button_t Tare;
	Button_t Net;
	Button_t Unit;
	Button_t Fn;
	Button_t Print;
	Key_Intent_t Intent;
} KeyBrd_t;

void init_keybrd(KeyBrd_t * pK);
void scan_keybrd(KeyBrd_t * pK);

#endif /* KEY_H_ */
